<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>清除浮动</title>
    <!-- 方法3：为父元素设置一定高度-->
    
    <style type="text/css">
        .box1 {
            background: rebeccapurple;
            height:150px; 
        }

        .box2 {
            width: 100px;
            height: 100px;
            background-color: blue;
            float: left;
        }
    </style>
</head>

<body>

    <div class="box1">
        <div class="box2"></div>
    </div>

</body>

</html>